import csv
import pymysql

def save_mysql(row):  
    # print(type(row))     
    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='123456', db='airport_sample',charset="utf8")

    cursor = conn.cursor() 

    sql='insert into sample values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'

    effect_row = cursor.execute(sql,row)

    conn.commit()

    cursor.close()

    conn.close()



with open("sample_1k_tlts.csv",encoding='gb18030') as f: 
    f_cvs=csv.reader(f)
    # print(type(f_cvs))
    for row in f_cvs:
        if row[0]=="0":
            pass
        else:
            row2=[]
            # print(row)
            for i in row:
                # print(type(i))
                if i==" ":
                    i="  "
                # print(i)
                row2.append(i)
                # print(row2)
            save_mysql(row)
    print(type(row))

